package org.example.service;

import jakarta.annotation.Resource;
import org.example.entity.MyUser;
import org.example.entity.MyUserDetails;
import org.example.mapper.UserMapper;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;


@Service
public class MyUserDetailsService implements UserDetailsService {


    @Resource
    private UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        MyUser myUser = userMapper.getUserByName(username);
        if(myUser == null){
            throw new UsernameNotFoundException(username);
        }
        MyUserDetails userDetails = new MyUserDetails();
        userDetails.setMyUser(myUser);
        return userDetails;
    }
}